#!/bin/bash
#
# Copyright (c) Citrix Systems 2008. All rights reserved.
#
#   ./repeat n operation vm_name optional_args
#

if [ $# -le 2 ]; then 
   echo "usage: $0 n operation vm_name [optional arguments]"
   exit 1
fi 
N=$1
OP=$2
VM=$3
EXTRA=$4

MASTER=`xe pool-list params=master --minimal`
START=$(date +%s)

echo "# vm_number cumulative_time load_average"

perform () {
    i=$1
    TMP=`xe vm-${OP} ${EXTRA} vm=${VM}${i}`
    CURR=$(date +%s)
    DIFF=$(( ${CURR} - ${START} ))
    LOADAVG=`xe host-data-source-query data-source=loadavg host=${MASTER}`
    echo "${i} ${DIFF} ${LOADAVG}";
}

for i in `seq 1 ${N}`; do 
    perform $i
done
